package com.example.uploadtest.utils;

import com.alibaba.fastjson.JSON;
import com.example.uploadtest.webSocket.entity.pull.PullCanvasDto;
import com.example.uploadtest.webSocket.entity.push.BasePushDto;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.ConcurrentMap;


public class WsUtil {


    /**
     * 登录成功给自己回复
     * @return
     */
    public static String LoginSuccess(){
        BasePushDto send = new BasePushDto();
        send.setType(1);
        send.setData("login success");
        return JSON.toJSONString(send);
    }

    /**
     * 清空某人的缓存
     * @param canvse
     * @param user
     * @param group
     */
    public static void ClearUsLocal(ConcurrentMap<Integer, ArrayList<PullCanvasDto>> canvse, String user, Integer group) {
        Iterator<PullCanvasDto> iterator = canvse.get(group).iterator();
        while (iterator.hasNext()){
            if(user.equals(iterator.next().getUserid())){
                    iterator.remove();
            }
        }
    }

}
